<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{ item }}</li>
  </ul>
  <ul>
    <li v-for="p in productArr">{{ p }}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>商品编号</th>
      <th>商品品牌</th>
      <th>商品价格</th>
      <th>商品数量</th>
      <th>操作</th>

    </tr>
    <tr  v-for="(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const productArr = ref([
  {title: 'xiaomi', price: 1000, num: 1},
  {title: 'huawei', price: 2000, num: 2},
  {title: 'oppo', price: 3000, num: 3},
  {title: 'vivo', price: 4000, num: 4},
  {title: 'apple', price: 5000, num: 5}
])
const del=(index)=>{
  if (confirm('确定删除吗？')){
    productArr.value.splice(index,1)
  }
}

</script>

<style scoped>

</style>